/**
 * 
 * @author BJS aka Zephyr
 * @version 0.5
 * @date 2012-03-08
 * 
 */

var com;
if(!com) com = {};
else if( typeof com != 'object') throw new Error("com already exists and is not an object");
if(!com.zpyr) com.zpyr = {};
else if( typeof com.zpyr != 'object' ) throw new Error("com.zpyr already exists and is not an object");

com.zpyr.List = function() {
	this.oArray = new Array();
};
com.zpyr.List.prototype.put = {/*object*/};
com.zpyr.List.prototype.getIdx = {/*object*/};
com.zpyr.List.prototype.contains = {/*object*/};
com.zpyr.List.prototype.getByIdx = {/*idx*/};
com.zpyr.List.prototype.getByObject = {/*idx*/};
com.zpyr.List.prototype.getListByArray = {/*idx*/};
com.zpyr.List.prototype.remove = {/*idx*/};
com.zpyr.List.prototype.clear = {};

com.zpyr.List.prototype.put = function( object ) {
	this.oArray.push(object);
};

com.zpyr.List.prototype.getIdx = function( object ) {
	var retidx = -1;
	for( var i = 0 ; i < this.oArray.length ; i++) {
		if( com.zpyr.Util.equals( object , this.oArray[i] ) ) {
			return i;
		}
	}
	return retidx;
};

com.zpyr.List.prototype.contains = function( object ) {
	return this.getIdx( object ) == -1? false : true;
};

com.zpyr.List.prototype.getByIdx = function( idx ) {
	return this.oArray[idx];
};

com.zpyr.List.prototype.getByObject = function( object ) {
	return this.getByIdx( this.getIdx( object ) );
};

com.zpyr.List.prototype.getListByArray = function(  ) {
	return this.oArray;
};

com.zpyr.List.prototype.remove = function( idx ) {
	
	this.oArray = this.oArray.slice(0 , idx).concat( this.oArray.slice(idx+1 , this.oArray.length) );
};

com.zpyr.List.prototype.clear = function() {
	this.oArray = new Array();
};


com.zpyr.StorageList = new com.zpyr.Class({
	name : "StorageList" ,
	extend : com.zpyr.List , 
	construct : function(storageKey) {
		this.superclass();
		this.storageKey = storageKey;
		this.getStorage();
	},
	methods: {
		setStorage: function() {
			var str = com.zpyr.Util.objToStr( this.oArray );
			localStorage.setItem(this.storageKey , str);
		},
		getStorage: function() {
			var str = localStorage.getItem( this.storageKey );
			this.oArray = com.zpyr.Util.strToArray( str );
		},
		put: function(object) {
			this.oArray.push(object);
			this.setStorage();
		},
		clear: function() {
			this.superclass.prototype.clear.call(this);
			this.setStorage();
		}
	}
});
